﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using System.Dynamic;
using Facebook;

namespace Version2
{
    /// <summary>
    /// Facebook is a fairy!!
    /// </summary>
    public class FacebookUtil
    {
        //    App ID/API Key
        static string app_id = "287671121361498";
        //App Secrete
        static string secret = "1994c1172fb3e0cc5de39106c211ab6d";

        private static ILog logger = LogManager.GetLogger(typeof(FacebookUtil));


        public static void getStuff()
        {
            FacebookClient c = new FacebookClient();
            c.AppId = app_id;
            c.AppSecret = secret;

            /*dynamic parameters = new ExpandoObject();
            parameters.q = "watermelon";
            parameters.type = "post";
            parameters.fields = "from.name,message";

            dynamic results = c.Get(parameters);

            foreach (var post in results[0].data)
            {
                // Based simply on API desciptors.
                //Console.WriteLine("Post-> {0}: {1}", post.from.name, post.message);
            }*/

            Console.WriteLine("LOCATION--");

            dynamic q = new ExpandoObject();
            // Must have something here.
            q.q = "the";
            // Maybe needs to be location? Nope, don't have permission. Would need to log in to account.
            q.type = "post";
            // Space needle lat/lon
            double space_needle_lat = 47.619920;
            double space_needle_lon = -122.348725;
            q.center = String.Format("{0},{1}", space_needle_lat, space_needle_lon);
           // q.limit = 500;
//            q.since = DateTime.Now.AddMinutes(-300).Millisecond;
            //q.distance = "1000";

            dynamic results = c.Get(q);
            if (results == null || results[0] == null)
            {
                Console.WriteLine("Could not find any data for geo query");
                return;
            }

            Console.WriteLine("Found {0} results", results[0].data.Count);
            //for (int i = 0; i < 2; i++)
            //{
            foreach (var data in results[0].data)
            {
                if (data.place != null)
                    Console.WriteLine("{0}: \"{1}\"", data.from.name, data.message);
                if (data.location != null)
                    Console.WriteLine("{0}: \"{1}\"", data.from.name, data.message);
            }
            //}
            // Only if you have an access token.
            /*dynamic friendListData = c.Get("/me/friends/");

            foreach (var friend in friendListData.data)
            {
                Console.WriteLine(friend["id"].ToString().Replace("\"", ""));
                Console.WriteLine(friend["name"].ToString().Replace("\"", ""));
            }*/

        }
    }
}
